Basic Graphics Programming

Table of Contents

This assignment is to be done individually. You can talk to other people in the class, me (Dave), the prefect, and lab assistants for ideas and to gain assistance. You can help each other debug programs, if you wish. The code that you write should be your own, however, and you shouldn’t hand a printout of your program to others. See the course syllabus for more details or just ask me if I can clarify.

Get started

Create a folder in which to store your work for this assignment.

  • If you are working on your own computer, it’s up to you where to put the folder. Your desktop is likely as good a place as any. Make a folder titled drawing1.
  • If you are working in the labs in Olin, make sure to first mount the COURSES folder, so that you won’t lose your code when you log out. Once you’ve done so, open up Finder, then navigate to your personal student work folder. You can then make a drawing1 folder within there.
  • Using your web browser, save this graphics.py file to the folder you created in the step above.
  • Once you’ve done so, you should then open up your new folder in VS Code. To do so, start up VS Code, then drag your folder onto the VS Code window. This should open up the folder within VS Code. If you are asked, click that you trust the authors. You should see the graphics.py file inside it. If you don’t, that means you saved it into the wrong location with your browser, or you’ve opened the wrong folder. Try again, or ask for help before going ahead.

The graphics.py module

You can open up graphics.py and look at it if you’d like. However, we won’t be paying much attention for a while to what’s inside it. Instead, we’re going to use this module in our own programs.

Now similarly grab the file myArtwork.py and open it up.

Make sure to pay attention in particular to how the square that I draw has a size that is relative to the size of the graphics window. Try changing the line in the program that sets the size of the window and return; observe how the rectangle scales.

To run your program, in the terminal window, type:

python myArtwork.py

Modify the program to accomplish the following:

  • Change the background color. Pick your favorite.
  • Draw an additional square centered in the figure of a scale that you choose, but make it scale proportionately to the size of the whole window, just like my rectangle does. When I say that you should draw your square centered, I mean that the very center of the square should be the center of the window. Make sure that you draw a square, not a rectangle, regardless of what width and height the window has.
  • Instead of fixing the size of the window in the code, have the program ask the user (using input) what the length and the width of the window should be. Then draw the window accordingly.

Here is the documentation for graphics.py. (A link is also on the Moodle home page). Take a few minutes to skim through the documentation to familiarize yourself with what’s there, and where. Then try picking out a few methods that look like they might be interesting, and try them out. Modify your program to use other methods from this documentation page.

Your Own Design

Write a new Python program named drawing.py. Draw a picture of your own design and be creative. Use at least two new methods in the graphics library that my program didn’t use, at least 3 colors (in addition to the background), and at least 3 distinct shapes of some sort within that don’t connect to each other. Creativity is encouraged!

Grading

You’ll receive a grade of M for the assignment if you successfully achieve the three bulleted tasks laid out in the section above labeled “The graphics.py module.” You’ll receive a grade of E if you achieved an M, and if you have also completed the “Your own design” task above.

What to turn in

Turn in a zip file of your work to Moodle. Do this by zipping (compressing) the entire folder, not each individual file. Here are instructions on how to do this on a Mac, and on Windows.

Author: Dave Musicant